package com.yq.controller;

import com.yq.model.BaseVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpSession;

/**
 * @author: 杨庆
 * @since: 2022.9.3 15:20
 * @description:
 */

@RestController
public class UserController {

    @RequestMapping("login")
    public BaseVO login(String username, String password, HttpSession session){
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){
            return BaseVO.error("用户信息错误");
        }
        session.setAttribute("username",username);
        return BaseVO.ok();
    }

    @RequestMapping("hello")
    public BaseVO hello(@SessionAttribute("username")String username){
        if (username==null){
            return BaseVO.error("没有登录");
        }
        return BaseVO.ok(username);
    }

}
